function SLC = complArrGen(SigSegmData,L,NL)
%complArrGen - Generation of data array for time series segment characterization
%
%   SLC = complArrGen(SigSegmData,L,NL)
%
% The output SLC is a N-by-6-by-NL cell variable such that 
%   SLCk = SLC(:,:,k) = {tRef,ttIn,ttFin,tR1,tR2,filena}
% contains the relevant data about the time series segments for the level k
% generated from the inputs
%   L = [tRef,ttIn,ttFin,ClassTS],
% provided by trendClass, and
%   SigSegmData = {tRef,tR1,tR2,filena},
% provided by PluVelScalogram.
% Clearly, the undefined data (L(:,4) = 0) are not used in SLC generation.
%                                
% See also PluVelScalogram, trendClass, dataHomAug.

% G. Teza, 2020

nrl = size(L,1);
nrs = size(SigSegmData,1);
if nrl ~= nrs
    error('Incompatible input data'); 
end

if NL == 7
    SLC = cell(7,1);
else
    SLC = cell(4,1);
end

I4 = L(:,4);
for k = 1:NL
    Ik = I4 == k;
    Lk = L(Ik,1:3);
    LCk = num2cell(Lk);
    nk = size(Lk,1);   
    SLCk = cell(nk,6);
    SLCk(:,1:3) = LCk;
    Sk = SigSegmData(Ik,2:4); 
    SLCk(:,4:6) = Sk;
    SLC(k) = {SLCk};
end